const fs = require("fs");
const path = require("path");
const readline = require("readline");

// 文件名
const fullFileName = path.join(__dirname, "../", "../", "logs", "access.log");
// 创建 readStream
const rs = fs.createReadStream(fullFileName);
// 创建 readline 对象
const rl = readline.createInterface({
  input: rs,
});

let chromeNum = 0;
let sum = 0;

// 逐行读取
rl.on("line", (lineData) => {
  if (!lineData) return;
  sum++; // 记录总行数
  const arr = lineData.split(" -- "); // 拆分
  if (arr[2] && arr[2].includes("Chrome")) {
    chromeNum++;
  }
});

// 读取完成
rl.on("close", () => {
  console.log(chromeNum, sum, "chrome 占比：" + chromeNum / sum);
});
